<?php
/**
 * D5Power Studio d5power Webgame Engine
 *
 * Extends DOTK system
 * Author: D5Power Studio
 *
 *
 * 第五动力工作室 d5power网页游戏引擎 Ver 1.0
 * 继承自:DOTK引擎
 * 作者：第五动力工作室
 */

/** PAGE NOT ALLOWED
 * Verify if user called this page through a allowed page.
 * @message: That file cannot be displayed alone.
 */
if (!isset($allowed_page)) { echo "That file cannot be displayed alone."; exit; }

require_once("d5power.DAO.php");

/**
* Dotk Battle class
*
* Critical hit = 20
* Critical miss = 1
* Dexterity bonus = Dexterity/8
* Strength bonus = Strength/6
*/
class Battle extends DAO {

  //reference to my character
  public $me;
  //reference to the opponent character
  public $opponent;
  public $preemptive_char;
  public $turncount;
  //If I'm the preemptive character, then
  //my turn_type will be the EVEN ones, else ODD ones.
  public $turn_type;
  private $in_fight = false;
  public $battle_id;
  public $status;
  public $d5m;

  /**
  * Class constructor
  */
  public function Battle() {
    
  }

	public function getBattle_id()
	{
		
	}
	
	public function setBattle_id($battle_id)
	{
		
	}
	
	public function getStatus()
	{
		
	}
	
	public function setStatus($status)
	{
		
	}
	
	public function checkStatus()
	{
		
	}

  /**
  * Function preemptive
  * @description Define which character will start the battle (initiative calc)
  */
  private function preemptive() {
    
  }


	/**
	 * Function create
	 * @description Used to initiate a new battle.
	 * @param {Character} $me
	 * @param {Character} $opponent
	 */
	public function create($me, $opponent)
	{

	}
	
	/**
	 *	战斗结束，清除内存信息
	 *	
	 *	
	 *	
	 */
	public function clearBattle()
	{
		
	}


  /**
  * Function defineTurn
  * @description
  */
  private function defineTurn($preemptiveId=0) {
  	
  }
  
	public function getTurn()
	{
		return $this->turn_type;
	}

  /**
  * 
  */
  private function endTurn() {
  	/*
    $sql = "insert into battle_messages(battle_id, turn, affected_char, damage) values(?,?,?,?)";
    try {
      $result = $this->retrieve($sql, array($this->battle_id, $this->turncount, $this->me->getCharacterId(), 0));
    }
    catch(Exception $e) {
      print_r(array($this->battle_id, $this->turncount, $this->me->getCharacterId(), 0));
    }

    $this->turncount++;
	*/
  }

  /**
  * Function recuseBattle
  */
  public function recuseBattle() {
    
  }


  /**
  * Function acceptBattle
  * @description
  */
  public function acceptBattle() {
    
  }


  /**
  * Function attack
  */
  public function attack() {
    
  }

	public function changeTurn()
	{
		
	}

  /**
  * Function load
  * @description Used to load all attributes of a battle with a given $battle_id.
  * @param {Character} $my_character Instance of my character
  * @param {Character} $opponent
  * @param {Integer} $battle_id
  */
  public function load(& $my_character, & $opponent, & $preemptive_char, $battle_id) {
    
  }


	/**
	* Function save
	* @description Used to save the battle data.
	*/
	public function save()
	{
		
	}


  /**
  * Function inFight
  * @description Verify if there is a battle in course.
  */
  public function inFight() {
    if($this->status == "IN FIGHT") {
      return true;
    }
    else {
      return false;
    }
  }

} // end class
?>